package com.yanqu.road.logic.activity.wealthscroll;

import com.yanqu.road.dao.impl.activity.wealthscroll.WealthScrollConfigDaoImpl;
import com.yanqu.road.entity.activity.ActivityConfig;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.wealthscroll.config.WealthScrollTaskConfig;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.utils.string.StringUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 新财神密卷配置
 */

public class WealthScrollConfig {
    //任务map
    private Map<Integer, WealthScrollTaskConfig> taskConfigMap = new HashMap<Integer, WealthScrollTaskConfig>();
    //活动
    private ActivityInfo activityInfo;
    //积分以及购买道具
    private int scoreItem;
    //经验道具
    private int expItem;
    //每级经验
    private int eachLevelExp;
    //新财神秘卷--购买进阶秘卷后提升的秘卷等级（立即提升xx级秘卷等级）
    private int advanceLevelUp;
    //新财神秘卷--购买豪华秘卷后提升的秘卷等级（立即提升xx级秘卷等级）
    private int luxuryLevelUp;
    //每一期的时长 /天
    private int sustainDay;
    //一键领取需要玩家等级
    private int oneKeyNeedLv;
    //新财神秘卷--循环起始期数，找不到下一期配置后，从第n期开始循环
    private int loopStartNo;
    //财神密卷最大期数
    private int loopEndNo;
    //复购最大期数
    private int repeatBuyMax;


    public WealthScrollConfig(ActivityInfo activityInfo, Map<String, ActivityConfig> activityConfigMap) {
        this.activityInfo = activityInfo;
        this.taskConfigMap = new WealthScrollConfigDaoImpl().getWealthScrollTaskConfigMap(activityInfo.getActivityId());

        int loopMaxEndNo = 0;
        int tempRepeatBuyMax = 0;
        for (WealthScrollTaskConfig config : taskConfigMap.values()) {
            config.setCompleteParamList(StringUtils.stringToIntegerList(config.getCompleteParams(),"\\|"));
            String rewards = config.getRewards();
            Map<Integer,String> tempRewardMap = new ConcurrentHashMap<>();
            List<String> strings = StringUtils.stringToStringList(rewards, "\\|");

            //如果是进度奖励 算出一个最大期数
            if(config.getCompleteType() == eGamePlayerEventType.WealthScrollExpProcess.getValue()){
                int maxNo = 0;
                for (String reward : strings) {
                    maxNo++;
                    tempRewardMap.put(maxNo, reward);

                }
                if (loopMaxEndNo == 0){
                    loopMaxEndNo = maxNo;
                }else {
                    if (loopMaxEndNo > maxNo){
                        //配置又错了 但是要给他限制住
                        loopMaxEndNo = maxNo;
                    }
                }
            } else if (config.getCompleteType() == eGamePlayerEventType.WealthScrollRepeatBuyTime.getValue()){
                int maxNo = config.getCompleteParamList().get(3);


                if (tempRepeatBuyMax == 0){
                    tempRepeatBuyMax = maxNo;
                }else {
                    if (maxNo>tempRepeatBuyMax){
                        tempRepeatBuyMax = maxNo;
                    }
                }
            }
            config.setRewardMap(tempRewardMap);
        }

        //设置最大新财神密卷期数
        this.loopEndNo = loopMaxEndNo;
        //设置最大复购奖励
        this.repeatBuyMax = tempRepeatBuyMax;

        this.scoreItem = activityConfigMap.get("EXCHANGE_SCORE_ITEM_ID").getIntValue();
        this.expItem = activityConfigMap.get("WEALTH_SCROLL_EXP_ID").getIntValue();
        this.eachLevelExp = activityConfigMap.get("WEALTH_SCROLL_EACH_EXP").getIntValue();

        List<Integer> addLevelList = activityConfigMap.get("WEALTH_SCROLL_BUY_GIFT_LEVEL").getIntListValue("\\|");
        this.advanceLevelUp = addLevelList.get(0);
        this.luxuryLevelUp = addLevelList.get(1);

        this.sustainDay = activityConfigMap.get("WEALTH_SCROLL_EACH_DATE").getIntValue();
        this.oneKeyNeedLv = activityConfigMap.get("WEALTH_SCROLL_GET_ALL_REWARD_NEED_LV").getIntValue();
        this.loopStartNo = activityConfigMap.get("WEALTH_SCROLL_CYCLE_START_NUM").getIntValue();

    }

    public Map<Integer, WealthScrollTaskConfig> getTaskConfigMap() {
        return taskConfigMap;
    }

    public ActivityInfo getActivityInfo() {
        return activityInfo;
    }

    public int getScoreItem() {
        return scoreItem;
    }

    public int getExpItem() {
        return expItem;
    }

    public int getEachLevelExp() {
        return eachLevelExp;
    }

    public int getAdvanceLevelUp() {
        return advanceLevelUp;
    }

    public int getSustainDay() {
        return sustainDay;
    }

    public int getOneKeyNeedLv() {
        return oneKeyNeedLv;
    }

    public int getLoopStartNo() {
        return loopStartNo;
    }

    public WealthScrollTaskConfig getTaskConfig(int taskId) {
        return taskConfigMap.get(taskId);
    }

    public int getActivityId(){
        return activityInfo.getActivityId();
    }

    public int getLoopEndNo() {
        return loopEndNo;
    }

    public int getLuxuryLevelUp() {
        return luxuryLevelUp;
    }

    public int getRepeatBuyMax() {
        return repeatBuyMax;
    }
}
